db.company.insert(
   {
     loc : { type: "Point", coordinates: [ 116.482451, 39.914176 ] },
     name: "大望路地铁",
     category : "Parks"
   }
)

db.company.insert(
   {
     loc : { type: "Point", coordinates: [ 116.492451, 39.934176 ] },
     name: "test1",
     category : "Parks"
   }
)

db.company.insert(
   {
     loc : { type: "Point", coordinates: [ 116.462451, 39.954176 ] },
     name: "test2",
     category : "Parks"
   }
)


db.company.insert(
   {
     loc : { type: "Point", coordinates: [ 116.562451, 38.954176 ] },
     name: "test3",
     category : "Parks"
   }
)

db.company.insert(
   {
     loc : { type: "Point", coordinates: [ 117.562451, 37.954176 ] },
     name: "test4",
     category : "Parks"
   }
)

db.company.ensureIndex( { loc : "2dsphere" } )
db.company.getIndexes()
db.company.dropIndexes()

db.company.find({
    "loc" : { 
        "$geoWithin" : {
          "$center":[[116.482451,39.914176],0.05]
        }
    }
})
/** 计算中心点最近的三个点 */
db.company.aggregate([
   {
     $geoNear: {
        near: { type: "Point", coordinates: [116.482451,39.914176 ] },
        key: "loc",
        distanceField: "dist.calculated"
     }
   },
   { $limit: 3 }
])

/** 2d 测试  */
db.places.drop()
db.places.insert({"name": "Temple1","tile": [32, 22]})
db.places.insert({"name": "Temple2","tile": [30, 22]})
db.places.insert({"name": "Temple3","tile": [28, 21]})
db.places.insert({"name": "Temple4","tile": [34, 27]})
db.places.insert({"name": "Temple5","tile": [34, 26]})
db.places.insert({"name": "Temple6","tile": [39, 28]})

db.places.find({})
 
db.places.ensureIndex({"tile" : "2d"}, {"min" : -90, "max" : 90, "bits" : 20}) 
 
db.places.find({"tile": {"$within": {"$box": [[0, 0], [30, 30]]}}})